<template>
	<view class="btn" @click="payFun">
		{{name?name:''}}
	</view>
</template>

<script>
	export default {
		props:{
			name:{
				type:String,
				default:"",
				// default:"支付",
			}
		},
		components: {
		},
		data() {
			return {
				imgUrl:this.$apiFun.imgUrl,
				host:this.$apiFun.host,
			}
		},
		onLoad() {
		},
		methods: {
			payFun(data){
				var that = this
				data.nonceStr&&uni.requestPayment({
					provider: 'wxpay',//支付方式简写
					// data,
					appId: data.appId, //小程序Appid
					timeStamp:data.timeStamp , //创建订单时间戳
					nonceStr: data.nonceStr,
					package: data.package, // 订单包
					signType: data.signType, // 加密方式统一'MD5'
					paySign: data.sign, // 后台支付签名返回
					success: function (res) {
						console.log('success:' + JSON.stringify(res));
						that.$emit('paySuccess')
					},
					fail: function (err) {
						console.log('fail:' + JSON.stringify(err));
						uni.showToast({
							title:'支付失败',
							icon:'none'
						})
						that.$emit('payFail')
					}
				});
			},
		},
		onReachBottom() {
			
		}
	}
</script>

<style scoped lang="less">
	page{
		width: 100%;
		height: 100%;
		.btn{
			width: 100%;
			height: 100%;
			white-space: nowrap;
		}
	}
</style>
